<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="/MES_Project/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
	function creatXhr(){
		if(window.ActiveXObject){
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			xhr = new XMLHttpRequest();
		}
	}
	
	function test1(i){
		if(i==undefined){
			var i = 0;
		}
			id1=setTimeout("getHello2("+i+")",3000);
	}
	function test2(i){
		if(i==undefined){
			var i = 0;
		}
			id3=setTimeout("getHello3("+i+")",5000);
	}
	function test3(i){
		if(i==undefined){
			var i = 0;
		}
			id6=setTimeout("getHello4("+i+")",7000);
	}
	function test4(){
		 location.href("operate_result.do"); 
	}
	function getHello2(i){
		var totalNum = 0;
		var num = 1;
		totalNum =  i + num;
		var a=${sessionScope.startProductEA};
		creatXhr();
		var quertString = "i="+i;
		xhr.onreadystatechange = callback;
		xhr.open("POST","operating_machineA.do",true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send(quertString);
		if(totalNum == a){
			cleartTimeout(id);
			cleartTimeout(id1);
			cleartTimeout(id2);
		}else{
			id=setTimeout("test1("+totalNum+")",2000);
			if(totalNum==1){
				id2=setTimeout("test2()",2000);
			}
		}
	}
	
	function callback(){
		if(xhr.readyState==4){
			if(xhr.status==200){
				var restTxt = xhr.responseText;
				document.getElementById("result_machineA").innerHTML = restTxt;
			}else{
				alert("요청에 대한 처리를 하지 못햇습니다.: "+xhr.status);
			}
		}
	}
	function getHello3(i){
		var totalNum = 0;
		var num = 1;
		totalNum =  i + num;
		var a=${sessionScope.startProductEA};
		creatXhr();
		var quertString = "i="+i;
		xhr.onreadystatechange = callback1;
		xhr.open("POST","operating_machineB.do",true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send(quertString);
		if(totalNum == a){
			cleartTimeout(id3);
			cleartTimeout(id4);
			cleartTimeout(id5);
		}else{
			id4=setTimeout("test2("+totalNum+")",2000);
			if(totalNum==1){
				id2=setTimeout("test3()",2000);
			}
		}
	}
	function callback1(){
		if(xhr.readyState==4){
			if(xhr.status==200){
				var restTxt = xhr.responseText;
				document.getElementById("result_machineB").innerHTML = restTxt;
			}else{
				alert("요청에 대한 처리를 하지 못햇습니다.: "+xhr.status);
			}
		}
	}
	function getHello4(i){
		var totalNum = 0;
		var num = 1;
		totalNum =  i + num;
		var a=${sessionScope.startProductEA};
		creatXhr();
		var quertString = "i="+i;
		xhr.onreadystatechange = callback2;
		xhr.open("POST","operating_machineC.do",true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send(quertString);
		if(totalNum == a){
			test4();
			cleartTimeout(id5);
			cleartTimeout(id6);
			cleartTimeout(id7);
		}else{
			id7=setTimeout("test3("+totalNum+")",2000);
		}
	}
	function callback2(){
		if(xhr.readyState==4){
			if(xhr.status==200){
				var restTxt = xhr.responseText;
				document.getElementById("result_machineC").innerHTML = restTxt;
			}else{
				alert("요청에 대한 처리를 하지 못햇습니다.: "+xhr.status);
			}
		}
	} 
	
	function openPop(id){
		window.open("/MES_Project/show_pop.do?id="+id+"&count="+${sessionScope.startProductEA}, "popup", "left=450, top=400, width=700, height=500, resizable=no, scrollbars=yes, status=no");
	}
	$(document).ready(function(){
		$("#a").live('click',function(){
			window.open("/MES_Project/show_pop.do?id="+"a", "popup", "left=450, top=400, width=1000, height=1000, resizable=no, scrollbars=yes, status=no");
		});
		$("#b").live('click',function(){
			window.open("/MES_Project/show_pop.do?id="+"b", "popup", "left=450, top=400, width=1000, height=1000, resizable=no, scrollbars=yes, status=no");
		});
		$("#c").live('click',function(){
			window.open("/MES_Project/show_pop.do?id="+"c", "popup", "left=450, top=400, width=1000, height=1000, resizable=no, scrollbars=yes, status=no");
		});
	});
</script>
<style type="text/css">
.machineCss{
	float: left;
	margin-top: 100px;
	margin-left: 150px;
}
</style>
</head>
<body onload="test1()">
	<form id="send" method="post">
		
		<div>
			<h2>공정과정</h2><hr>
		</div>
		<div id="machineContainer">
			<div id="result_machineA">
				<img src="/MES_Project/img/A.JPG" id="a" name="a" width="200" height="100" class="machineCss" onclick="javascript:openPop('a')">
			</div>
			<div id="result_machineB">
				<img src="/MES_Project/img/B.JPG" id="b" name="b" width="200" height="100" class="machineCss" onclick="javascript:openPop('b')">
			</div>
			<div id="result_machineC">
				<img src="/MES_Project/img/C.JPG" id="c" name="c" width="200" height="100" class="machineCss" onclick="javascript:openPop('c')">
			</div>
		</div>
	</form>
	
</body>
</html>